//
//  BaseTableViewController.swift
//  sinaweiboFirst
//
//  Created by mac on 16/3/7.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit 

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {
   
    var userLogin = UserAccount.shareAccount.userLogin
    
    //访客视图属性
    var visitorLoginView: VisitorLoginView?
    
    //在根视图没有被实例化之前 不要追踪view 会造成递归
    override func loadView() {
        if userLogin {
            //显示数据->加载tableView
            super.loadView()
            
        }else{
            
            visitorLoginView = VisitorLoginView()
            
            view = visitorLoginView
            
//--------------指定代理------------------------
            visitorLoginView?.visitorDelegate = self
            
            
            //左边登录 右边注册 navigationItem
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
        }
    }
    
//-----------------协议方法------------------
//OC不实现协议方法报警告 swift不实现 就会报错
    func userWillLogin() {
        print("用户登录")
        
        let oauth = OAuthViewController()
        //包装在一个导航控制器中 进行modal
        let nav = UINavigationController(rootViewController: oauth)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        print("用户注册")
    }
   
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

}
